<?php

class AjaxController extends BeController {

    public function actionAddCurrency() {
        //echo json_encode($_POST);
        $price = $_POST['ProductObject']['price_USD'];
        
        $currencyCode = $_POST['currency'];
        
        
        $currency = Currency::model()->findByAttributes(array('codeTo' => $currencyCode));
        $form = '';
        if ($currency) {
            $data = array();
            $val = ($price * $currency->conversionRate) ? ($price * $currency->conversionRate) : 0;
            $form = '<div class="tab-content default-tab" id="extra_box_' . $currency->codeTo . '">
                         <label class="required" for="ProductObject_price">Price [' . $currency->codeTo . '] <i style="color: #aaa;">(1USD = ' . $currency->conversionRate . ' ' . $currency->codeTo . ')</i></label>
                         <input type="text" value="' . $val . '" name="priceCurrency[' . $currency->codeTo . ']" style="width: 200px;">&nbsp;&nbsp;' .
                    CHtml::button("[ X ] Remove", array('class' => 'bebutton active', 'title' => "Remove currency", 'onclick' => 'js:deleteCurrency("' . $currency->codeTo . '");'))
                    . '</div>';
            $data['currency'] = $currency->codeTo;
            $data['rate'] = $currency->conversionRate;
            $data['form'] = $form;
            echo json_encode($data);
            Yii::app()->end();
        } else {
            echo 'false';
        }
    }

}
